#import "PointOfInterestCollection.h"

// Shared instance of PointOfInterestCollection
static PointOfInterestCollection* sharedPointOfInterestCollection = nil;

/**
 * A PointOfInterestCollection is an object representing a
 * collection of points of interest.
 *
 * @author      Justin Hollander
 * @version     0.7.0
 * @since       0.1.0
 * @see         PersistentDataCollection
 */
@implementation PointOfInterestCollection

/**
 * Retrieve the unique key used for archiving.
 *
 * @return  the key used for keyed archiving
 */
- (NSString*)getArchiveKey{
	@synchronized (self) {
		return @"4kmuoaj24506ms";
	}
}

/**
 * Retrieve the shared instance of the point of interest collection.
 *
 * @return  the shared instance of PointOfInterestCollection
 */
+ (PointOfInterestCollection*)sharedPointOfInterestCollection{
	@synchronized (self) {
		if (sharedPointOfInterestCollection == nil) {
			sharedPointOfInterestCollection = [[PointOfInterestCollection alloc] initWithFile:POI_FILENAME 
																			usingSubdirectory:POI_SUBDIRECTORY];
		}
	}
	
	return sharedPointOfInterestCollection;
}

/**
 * Get a sorted list of the point of interest categories.
 *
 * @return  a sorted list of the point of interest categories
 */
- (NSArray*)getSortedCategories {
	NSMutableArray* sortedCategories = [NSMutableArray array];
	NSArray* sortedPois = [[self getDataTypes] sortedArrayUsingSelector:@selector(compareCategory:)];
	
	for (PointOfInterest* poi in sortedPois) {
		if (![sortedCategories containsObject:[SFUConstants POICategoryString:poi.category]]) {
			[sortedCategories addObject:[SFUConstants POICategoryString:poi.category]];
		}
	}
	
	return sortedCategories;
}

@end
